import { Language } from "../../../../../extend/language/Language";
import { LongProgressBar } from "../LongProgressBar";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { AcupointData } from "./AcupointData";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { PulseSharedObject } from "../PulseSharedObject";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../../common/alertwins/CheckBoxWin";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class AcupointCountdown
    
    export  class AcupointCountdown /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._itemArrName = Language.getArray(30099);
            this._itemArr = [this._itemArrName[0], this._itemArrName[1]];
            this._itemCbArr = [];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc2=0;
            var loc4=null;
            this._prograssBar = new LongProgressBar();
            this._prograssBar.x = 5;
            this._prograssBar.y = 22;
            this._prograssBar.progressBarClass = ImagesConst.EnergyBar;
            this._prograssBar.setBgSize(160, 14);
            this._prograssBar.isHaveProgressPoint(true);
            this._prograssBar.setValue(0, 100);
            this._prograssBar.setLabelVisible(false);
            addChild(this._prograssBar);
            this._timeTf = new GTextFormat("", 12, 16776960);
            this._timeTxt = ObjCreate.createTextField("00: 00: 00", 80, 2, 80, 20, this, this._timeTf);
            var loc1=ObjCreate.createGTextField(Language.getString(30100) + "：", 5, 2, 60, 20, this, GlobalStyle.textFormat2);
            loc2 = 5;
            var loc3=40;
            var loc5=0;
            while (loc5 < this._itemArr.length) 
            {
                (loc4 = new GCheckBox()).styleName = "GCheckBox";
                loc4.name = this._itemArr[loc5].name;
                loc4.label = this._itemArr[loc5].label;
                loc4.width = 90;
                loc4.selected = false;
                loc4.buttonMode = true;
                loc4.x = loc2;
                loc4.y = loc3;
                loc3 = loc3 + loc4.height;
                loc4.addEventListener(flash.events.Event.CHANGE, this.onItemCbChangeHandler);
                this.addChild(loc4);
                this._itemCbArr.push(loc4);
                ++loc5;
            }
            this._goldTxt = ObjCreate.createTextField("0", 90, 43, 50, 20, this, this._timeTf);
            this._priceImg = GlobalClass.getBitmap(ImagesConst.Yuanbao_small);
            this._priceImg.x = 125;
            this._priceImg.y = 45;
            addChild(this._priceImg);
            this._speedUpBtn = ObjCreate.createGButton(Language.getString(30101), 100, -38, 65, 20, this, "Button");
            this._speedUpBtn.toolTipData = "<font color=\'#b1efff\'>" + Language.getString(30102) + "</font><br>";
            this._speedUpBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGrowthBtnClickHandler);
            this._speedUpBtn.enabled = false;
            this._speedUpBtn.visible = false;
            this._secTimer = new SecTimer();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerEnterFrameHandler);
            this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
            return;
        }

        public updateSpeedUpInfo(arg1: int=0): void
        {
            this._time = AcupointData.leftTimes;
            this._totalTime = arg1;
            if (this._time > 0) 
            {
                if (this._selectedAll) 
                {
                    (this._itemCbArr[0] as GCheckBox).selected = true;
                }
                this._timeTxt.text = RemainTimeTool.getRemainTimeBySeconds(this._time);
                this._timeTxt.setTextFormat(this._timeTf);
                this._speedUpBtn.enabled = true;
                this._speedUpBtn.visible = true;
                this._goldNum = Math.ceil(this._time / (5 * 60));
            }
            else 
            {
                this._timeTxt.text = "00: 00: 00";
                this._speedUpBtn.enabled = false;
                this._speedUpBtn.visible = false;
                this._prograssBar.setValue(this._time, this._totalTime);
            }
            if (this._selectedAll) 
            {
                this._goldTxt.text = Math.ceil(this._time / (5 * 60)).toString();
                this._goldTxt.setTextFormat(this._timeTf);
                this._priceImg.x = this._goldTxt.x + this._goldTxt.textWidth + 10;
            }
            this._secTimer.reset();
            this._secTimer.repeatCount = this._time;
            this._secTimer.start();
            return;
        }

        public stopTimer(): void
        {
            this._secTimer.stop();
            this._secTimer.isDelete = false;
            return;
        }

        /* internal  */onTimerEnterFrameHandler(arg1: SecTimer): void
        {
            if (arg1.repeatCount >= 0) 
            {
                this._time = arg1.repeatCount;
                this._timeTxt.text = RemainTimeTool.getRemainTimeBySeconds(this._time);
                this._timeTxt.setTextFormat(this._timeTf);
                if (this._selectedAll) 
                {
                    this._goldTxt.text = Math.ceil(this._time / (5 * 60)).toString();
                    this._goldTxt.setTextFormat(this._timeTf);
                    this._priceImg.x = this._goldTxt.x + this._goldTxt.textWidth + 10;
                    this._goldNum = Math.ceil(this._time / (5 * 60));
                }
                this._prograssBar.setValue(this._totalTime - this._time, this._totalTime);
            }
            return;
        }

        /* internal  */onTimerCompleteHandler(arg1: SecTimer): void
        {
            arg1.stop();
            arg1.isDelete = false;
            this._selectedAll = true;
            this._speedUpBtn.enabled = false;
            this._speedUpBtn.visible = false;
            this._prograssBar.setValue(0, 100);
            return;
        }

        /* internal  */onItemCbChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._itemCbArr.length) 
            {
                loc1 = this._itemCbArr[loc2];
                loc1.selected = false;
                ++loc2;
            }
            var loc3;
            (loc3 = arg1.target as GCheckBox).selected = true;
            var loc4=loc3.name;
            var loc5=loc4;
            switch (loc5) 
            {
                case "complete":
                {
                    this._goldNum = Math.ceil(this._time / (5 * 60));
                    this._goldTxt.text = this._goldNum.toString();
                    this._selectedAll = true;
                    this._timeMinute = Math.ceil(this._time / 60);
                    break;
                }
                case "oneHour":
                {
                    this._goldTxt.text = "12";
                    this._goldNum = 12;
                    this._selectedAll = false;
                    this._timeMinute = 60;
                    break;
                }
            }
            this._goldTxt.setTextFormat(this._timeTf);
            this._priceImg.x = this._goldTxt.x + this._goldTxt.textWidth + 10;
            return;
        }

        /* internal  */onGrowthBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (PulseSharedObject.isTodayNotTips("AcupointCountdown")) 
            {
                this.sureSpeedupOrNot();
            }
            else 
            {
                Alert.alertWinRenderer = CheckBoxWin;
                Alert.show(Language.getStringByParam(30153, this._goldNum), null, Alert.OK | Alert.CANCEL, null, this.onSureSpeedupClickHandler);
            }
            return;
        }

        /* internal  */sureSpeedupOrNot(): void
        {
            this._ownGold = Cache.instance.role.money.gold;
            if (this._goldNum <= this._ownGold) 
            {
                if (this._selectedAll) 
                {
                    this._timeMinute = Math.ceil(this._time / 60);
                }
                if (this._timeMinute > 0) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AcupointSpeedupUpgrade, this._timeMinute));
                }
            }
            else 
            {
                Alert.show(Language.getString(30103), null, Alert.OK | Alert.CANCEL, null, this.onClickHandler);
            }
            return;
        }

        /* internal  */onSureSpeedupClickHandler(arg1: int, arg2: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                this.sureSpeedupOrNot();
            }
            if (arg2) 
            {
                PulseSharedObject.save("AcupointCountdown", true);
            }
            return;
        }

        /* internal  */onClickHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
                Alert.resetToDefault();
            }
            return;
        }

        /* internal */ /* var */_timeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_goldTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_speedUpBtn: GButton;

        /* internal */ /* var */_timeTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_time: number;

        /* internal */ /* var */_totalTime: number;

        /* internal */ /* var */_goldNum: int;

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_itemArrName: Array<any>;

        /* internal */ /* var */_itemArr: Array<any>;

        /* internal */ /* var */_itemCbArr: Array<any>;

        /* internal */ /* var */_selectedAll: Boolean=true;

        /* internal */ /* var */_timeMinute: int=0;

        /* internal */ /* var */_ownGold: int;

        /* internal */ /* var */_prograssBar: LongProgressBar;

        /* internal */ /* var */_priceImg: Object /* flash.display.Bitmap */;
    }
